package com.duartepeixinho.P3D.Core.Geom 
{	
	import com.duartepeixinho.P3D.Core.Math.Vector3;
	/**
	 * P3D
	 * @version 0.1
	 * @author Duarte Peixinho
	 */
	public class Geometry
	{
		
		/**
		 * Public Vars
		 */
		public var vertices:Array = new Array();
		public var faces:Array = new Array();
		public var uvs:Array = new Array();
		public var updatedVertices:Array = new Array();
		/**
		 * Geometry
		 */
		public function Geometry() 
		{
			
		}
		
		/**
		 * Calculate Normals
		 */
		public function calcNormal():void {
			var  vA:Vector3, vB:Vector3, vC:Vector3, cb:Vector3, ab:Vector3;
			
			var vertices:Array;
			if (updatedVertices.length > 0) {
				vertices = updatedVertices;
			}
			else vertices = this.vertices;	
			
			for ( var f:uint = 0; f < this.faces.length; f++ ) {
			
				vA = vertices[ this.faces[ f ].a ];
				vB = vertices[ this.faces[ f ].b ];
				vC = vertices[ this.faces[ f ].c ];
				
				cb = vC.subVector(vB);
				ab = vA.subVector(vB);
				cb = cb.cross(ab);
				
				cb.normalize();			
				this.faces[ f ].normal = cb;
			}
		}
		

	}

}